<template>
  <div>
    <el-table ref="table" :data="dataSource">
      <el-table-column prop="stateName" label="状态" width="120">
        <template slot-scope="scope">
          <div class="box-dot">
            <span v-if="scope.row.state === 0" class="dot dot1" />
            <span v-else-if="scope.row.state === 1" class="dot dot2" />
            <span>{{ scope.row.stateName }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="200">
        <template slot-scope="scope">
          <el-button v-if="scope.row.state === 0" type="text" @click="thisUpDownShelf(scope.row, 1)">上架</el-button>
          <el-button v-if="scope.row.state === 1" type="text" style="color: red;" @click="thisUpDownShelf(scope.row, 0)">下架</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      stateList: [{ label: '待上架', value: 0 }, { label: '已上架', value: 1 }]
    }
  },
  methods: {
    // 上下架
    thisUpDownShelf(row, state) {
      let text = ''
      if (state === 0) {
        text = '下架'
      } else if (state === 1) {
        text = '上架'
      }
      this.$confirm(`确认将 ${row.auxiliaryName} ${text}吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$store.dispatch('app/setLoading', true)
        postAction('url', { no: row.no, state: state }).then(res => {
          if (res.status === 0) {
            this.$message.success(res.message || '操作成功！')
            this.loadData(1)
          }
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.box-dot{
  display: flex;
  align-items: center;
  .dot{
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
  }
  .dot1{
    background-color: #fea94b;
  }
  .dot2{
    background-color: #82d589;
  }
}
</style>

